package com.example.teachingSystem.controller;


import com.example.teachingSystem.pojo.form.BasePageQuery;
import com.example.teachingSystem.pojo.form.admin.AddAdminForm;
import com.example.teachingSystem.pojo.form.admin.UpdateAdminForm;
import com.example.teachingSystem.pojo.vo.AdminInfoVo;
import com.example.teachingSystem.service.AdminService;
import com.example.teachingSystem.utils.result.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSetMetaData;
import org.springframework.web.bind.annotation.*;
import com.example.teachingSystem.utils.result.Result;

@RestController
@RequestMapping("/admin")
@Tag(name="管理员管理模块")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/addAdmin")
    @Operation(summary = "添加管理员",security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> adminAddAdim(@RequestBody AddAdminForm addAdminForm){
        return  adminService.addAdminInfo(addAdminForm);
    }

    @DeleteMapping("/deleteAdmin/{adminId}")
    @Operation(summary = "删除管理员",security = {@SecurityRequirement(name = "Authorization")})
    public Result<String>deleteAdmin(@PathVariable Long adminId)
    {
        return adminService.deleteAdminInfo(adminId);
    }

    @GetMapping("/getById/{adminId}")
    @Operation(summary = "根据id获取管理员信息",security = {@SecurityRequirement(name = "Authorization")})
    public Result<AdminInfoVo>getAdminById(@PathVariable Long adminId){
        return adminService.getAdminById(adminId);
    }

    @GetMapping("/getAllAdmin")
    @Operation(summary = "获得管理员列表",security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<AdminInfoVo>getAllAdmin(@ParameterObject BasePageQuery basePageQuery){
        return adminService.getAllAdmin(basePageQuery);
    }

    @PostMapping("/updateAdmin")
    @Operation(summary = "修改管理员信息",security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> updateAdminInfo(@RequestBody UpdateAdminForm updateAdminForm){
        return adminService.updatedmin(updateAdminForm);
    }
}
